home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 May / Macworld (1998-05).dmg / Shareware World / Comms & Internet / ProTERM_1.2.5.Install / ProTERM Mac1.2.5 / Macros / Resident Library 1203 < prev    next >
Text File  |  1997-06-04  |  6KB  |  265 lines

  1. /****************************************
  2.  *                                      *
  3.  *  ProTERM/Mac Resident Macro Library  *
  4.  *                                      *
  5.  *   Version 1203  Updated 05/01/97     *
  6.  *                                      *
  7.  ****************************************/
  8.  
  9. /*
  10. This file is periodically updated by InTrec Software. As such, modifications to this file are not advised (because it becomes very difficult to move your changes to new versions of this file). Instead, make your changes to the Resident User # (where # is a number) file instead. That way, even if you get an updated version of Resident Library, your own personal macros remain unchanged within the Resident User # file.
  11.  
  12. The Resident User # files have precedence over the Resident Library file. Therefore, if you define duplicate routines or variables in the Resident User # files, they will be used instead of those in the Resident Library file.
  13. */
  14.  
  15. // special code to allow direct execution
  16. FUNC main()
  17. {
  18.  EXTERN(PREF_GET("mac1"),main(1));
  19.  RETURN;
  20. }
  21.  
  22. // make the library resident
  23. FUNC startup()
  24. {
  25.  SHARED STR _RLIB = "1022";
  26.  RESIDENT("",0,#KeyAccess+#LibAccess);
  27.  RETURN;
  28. }
  29.  
  30.  
  31. /***********************************************************************/
  32. /*                   Start of Library Macros                           */
  33. /***********************************************************************/
  34.  
  35. /*
  36. cmd_find(win_active(0),"resu^clt",0,0,0);
  37. */
  38.  
  39.  
  40. // find text
  41. FUNC cmd_find(INT win, STR find, INT from, INT uppr, INT dirc)
  42. {
  43.  STR result,from0,uppr0,dirc0;
  44.  
  45.  from0 = "start";
  46.  IF (from == 1) { from0 = "curs" }
  47.  uppr0 = "ignore";
  48.  IF (uppr == 1) { uppr0 = "exact" }
  49.  dirc0 = "forward";
  50.  IF (dirc == 1) { dirc0 = "reverse" }
  51.  
  52.  result = UI_CMD('^
  53.   cmd=find wind=%d find=&%*2s from=%s case=%s dir=%s
  54.  ',win,find,from0,uppr0,dirc0);
  55.  RETURN(UI_NUM("retn",0,result))
  56. }
  57.  
  58.  
  59. // replace text
  60. FUNC cmd_replace(INT win, STR find, STR repl, INT from, INT uppr, INT dirc)
  61. {
  62.  STR result,from0,uppr0,dirc0;
  63.  
  64.  from0 = "start";
  65.  IF (from == 1) { from0 = "curs" }
  66.  uppr0 = "ignore";
  67.  IF (uppr == 1) { uppr0 = "exact" }
  68.  dirc0 = "forward";
  69.  IF (dirc == 1) { dirc0 = "reverse" }
  70.  
  71.  result = UI_CMD('^
  72.   cmd=find wind=%d find=&%*2s repl=&%*2s from=%s case=%s dir=%s
  73.  ',win,find,repl,from0,uppr0,dirc0);
  74.  RETURN(UI_NUM("retn",0,result))
  75. }
  76.  
  77.  
  78. // start an ascii receive
  79. FUNC cmd_rcvasc(INT ses, STR file, INT line, INT ctrl, INT bit8)
  80. {
  81.  STR result;
  82.  
  83.  IF (!ses) { ses = WIN_FIND("","TERM") }
  84.  result = UI_CMD('
  85.     cmd=capt wind=%d file="%s" #save mode=%d ctrl=%d bit8=%d
  86.  ',ses,file,1+(line>0),(ctrl>0),(bit8>0));
  87.  RETURN(UI_NUM("retn",0,result));
  88. }
  89.  
  90.  
  91. // use uuundo to decode a file
  92. FUNC cmd_uuundo(STR file)
  93. {
  94.  INT run;
  95.  
  96.  run = IS_RUN("uuUN");
  97.  IF (!run) { F_LAUNCH(FN_TYPE("uuUN")) }
  98.  
  99.  UI_CMD('
  100.   cmd=apvt appl=@uuUN clas=@aevt kind=@odoc aeou="rqfi----file" file="%s"
  101.  ',file);
  102.  
  103.  IF (!run) { UI_CMD("cmd=apvt appl=@uuUN clas=@aevt kind=@quit") }
  104.  RETURN;
  105. }
  106.  
  107.  
  108. // send a file with ascii
  109. FUNC cmd_sndasc(INT ses, STR file, STR pmt, INT cp, INT lp, INT wid, INT blk)
  110. {
  111.  STR result;
  112.  STR cp0,lp0;
  113.  
  114.  IF (!IS_FILE(file)) { RETURN(0) }
  115.  IF (!ses) { ses = WIN_FIND("","TERM") }
  116.  
  117.  IF (IS_STR(cp)) { cp0 = cp }
  118.  IF (IS_NUM(cp)) { cp0 = STR_NUM(cp) }
  119.  IF (IS_STR(lp)) { lp0 = lp }
  120.  IF (IS_NUM(lp)) { lp0 = STR_NUM(lp) }
  121.  
  122.  result = UI_CMD('^
  123.  {onln cmd=session ptr=%d}
  124.  {from cmd=stream srcf="%s" +buf dstt=cmd conv=dot}
  125.  cmd=ascii strm=.from.strm sess=.onln.sess
  126.  prompt="%s" char="%s" line="%s" width="%d" blank="%d"
  127.  ',ses,file,pmt,cp0,lp0,wid,(blk>0));
  128.  RETURN(UI_NUM("wind",0,result));
  129. }
  130.  
  131.  
  132. // tell finder to update folder
  133. FUNC cmd_osupdt(STR folder)
  134. {
  135.  RETURN(UI_NUM("retn",0,UI_CMD('
  136.   cmd=apvt appl=@MACS clas=@fndr kind=@fupd
  137.   aeou="rqfi----file" file="%s"
  138.   aein="opnuerrnerrn"
  139.  ',folder)));
  140. }
  141.  
  142.  
  143. // tell finder to clean-up folder/file
  144. FUNC cmd_osclean(STR folder)
  145. {
  146.  RETURN(UI_NUM("retn",0,UI_CMD('
  147.   cmd=apvt appl=@MACS clas=@fndr kind=@fclu
  148.   aeou="rqfi----file" file="%s"
  149.   aein="opnuerrnerrn"
  150.  ',folder)));
  151. }
  152.  
  153.  
  154. // disconnect from the service
  155. FUNC cmd_hang(INT win)
  156. {
  157.  // if passed 0, find the window
  158.  IF (win == 0) {
  159.   win = NUM_LONG(SES_GET(0,"WIN"));
  160.  }
  161.  
  162.  // do the hangup
  163.  IF (win != 0) {
  164.   WT(0);
  165.   UI_CMD('
  166.    {onln cmd=sess ptr=%d}
  167.    cmd=online sess=.onln.sess opt=disc +status
  168.    {**** cmd=msg wind=%d msg=CLOS}
  169.   ',win,win);
  170.  }
  171.  RETURN(0);
  172. }
  173.  
  174.  
  175. // start another macro running (in its own thread space)
  176. FUNC cmd_macro(STR fname, INT ses)
  177. {
  178.  INT x;
  179.  INT win;
  180.  STR cli;
  181.  STR arg;
  182.  
  183.  // build the CLD for the macro exec
  184.  arg = "{term cmd=session #find}";
  185.  IF (ses != -1) {
  186.   arg = STR_FORMAT("{term cmd=session ptr=%u}", ses);
  187.  }
  188.  cli = STR_FORMAT("%s cmd=macro file=&%*2s sess=.term.sess", arg, fname);
  189.  
  190.  // add on the macro arguments
  191.  x = 3;
  192.  WHILE (x <= ARGC()) {
  193.   arg = "";
  194.   IF (IS_NUM(ARGV(x))) {
  195.    arg = STR_FORMAT(" parm=%d", ARGV(x));
  196.   }
  197.   IF (IS_STR(ARGV(x))) {
  198.    arg = STR_FORMAT(" parm=&%*2s", ARGV(x));
  199.   }
  200.   cli = cli + arg;
  201.   x = x + 1;
  202.  }
  203.  
  204.  // start execing macro and return window ident
  205.  win = UI_NUM("wind",0,UI_CMD(cli));
  206.  RETURN(win);
  207. }
  208.  
  209.  
  210. // make a ppp connection
  211. FUNC ppp_conn()
  212. {
  213.  INT err;
  214.  STR aevt;
  215.  
  216.  // send the connect apple event
  217.  aevt=ui_cmd('cmd=apvt appl=@FNDR clas=@netw kind=@RAco aein="opnuerrnerrn"');
  218.  // extract the error code
  219.  err = UI_NUM("errn",0,aevt);
  220. printf("aevt=%s^m",aevt);
  221. printf("err=%d^m",err);
  222.  // return error code
  223.  RETURN(err);
  224. }
  225.  
  226.  
  227. // disconnect ppp session
  228. FUNC ppp_disc()
  229. {
  230.  INT err;
  231.  STR aevt;
  232.  
  233.  // send the connect apple event
  234.  aevt=ui_cmd('cmd=apvt appl=@FNDR clas=@netw kind=@RAdc aein="opnuerrnerrn"');
  235.  // extract the error code
  236.  err = UI_NUM("errn",0,aevt);
  237.  // return error code
  238.  RETURN(err);
  239. }
  240.  
  241.  
  242. // return ppp status
  243. FUNC ppp_stat()
  244. {
  245.  INT err;
  246.  INT idx;
  247.  INT len;
  248.  STR aevt;
  249.  STR stat;
  250.  
  251.  // send the connect apple event
  252.  aevt=ui_cmd('cmd=apvt appl=@FNDR clas=@netw kind=@RAst aein="nutx----retn"');
  253.  // extract the status info
  254.  stat = UI_STR("retn",0,aevt);
  255.  // get index to connect info
  256.  idx = STR_INDEX("RAmsTEXT",stat);
  257.  IF (idx > 0) {
  258.   len = NUM_LONG(STR_MID(stat,idx+8));
  259.   RETURN(STR_MID(stat,idx+12,len));
  260.  }
  261.  // no status info available
  262.  RETURN("");
  263. }
  264.  
  265.